package com.wn.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wn.dao.ScenicDao;
import com.wn.entity.Catering;
import com.wn.entity.Scenic;
import com.wn.service.ScenicService;
import com.wn.utils.PageParam;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

/**
 * (Scenic)表服务实现类
 *
 * @author makejava
 * @since 2020-10-26 09:40:56
 */
@Service("scenicService")
@Transactional(rollbackFor = Exception.class)
public class ScenicServiceImpl implements ScenicService {
    @Resource
    private ScenicDao scenicDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Scenic queryById(String id) {
        return this.scenicDao.queryById(id);
    }

    /**
     * 动态查询
     * @param pageParam
     * @return
     */
    @Override
    public PageInfo<Scenic> searchSomeByPage(PageParam<Scenic> pageParam) {
        if(!StringUtils.isEmpty(pageParam.getSuperSearchKeyWord())){
            //执行高级检索
            //分页
            PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
            //排序
            for(int i=0;i<pageParam.getOrderParams().length;i++){
                PageHelper.orderBy(pageParam.getOrderParams()[i]);
            }


            List<Scenic> scenicList=scenicDao.superSearch(pageParam.getSuperSearchKeyWord());
            PageInfo<Scenic> scenicPageInfo = new PageInfo<Scenic>(scenicList);

            return scenicPageInfo;

        }else{
            //分页
            PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
            //排序
            for(int i=0;i<pageParam.getOrderParams().length;i++){
                PageHelper.orderBy(pageParam.getOrderParams()[i]);
            }


            List<Scenic> scenicList=scenicDao.searchSomeByPage(pageParam.getModel());
            PageInfo<Scenic> scenicPageInfo = new PageInfo<Scenic>(scenicList);

            return scenicPageInfo;

        }
    }


    /**
     * 新增数据
     *
     * @param scenic 实例对象
     * @return 实例对象
     */
    @Override
    public Integer insert(Scenic scenic) {
        scenic.setId(UUID.randomUUID().toString().replaceAll("-","")+"_scenic");
        return this.scenicDao.insert(scenic);
    }

    /**
     * 修改数据
     *
     * @param scenic 实例对象
     * @return 实例对象
     */
    @Override
    public Integer update(Scenic scenic) {

        return this.scenicDao.update(scenic);
    }

    @Override
    public List<Scenic> selScenic(Object longitude, Object latitude) {
        List<Scenic> scenic = scenicDao.selScenic(longitude, latitude);
        return scenic;
    }


}